local wezterm = require('wezterm')
local platform = require("utils.platform")

local act = wezterm.action
local mod = {}

if platform().is_mac then
   mod.SUPER = 'SUPER'
   mod.SUPER_REV = 'SUPER|SHIFT'
elseif platform().is_win or platform().is_linux then
   mod.SUPER = 'ALT'
   mod.SUPER_REV = 'CTRL|SHIFT'
end

local keys = {
   -- { key = "F1", mods = "NONE", action = "ActivateCopyMode" },
   -- { key = "F2", mods = "NONE", action = act.ActivateCommandPalette },
   { key = "F11", mods = "NONE", action = act.ToggleFullScreen },

   -- 复制/粘贴 --
   { key = "c", mods = "CTRL|SHIFT", action = act.CopyTo("Clipboard") },
   { key = "v", mods = "CTRL|SHIFT", action = act.PasteFrom("Clipboard") },

   -- tabs: spawn+close
   { key = "t", mods = mod.SUPER_REV, action = act.SpawnTab('CurrentPaneDomain') },
   { key = "w", mods = 'CTRL', action = act.CloseCurrentTab({ confirm = false }) },

   -- tabs: switch tab
   { key = "0", mods = mod.SUPER, action = act.ActivateTab(-1) },
   { key = "1", mods = mod.SUPER, action = act.ActivateTab(0) },
   { key = "2", mods = mod.SUPER, action = act.ActivateTab(1) },
   { key = "3", mods = mod.SUPER, action = act.ActivateTab(2) },
   { key = "4", mods = mod.SUPER, action = act.ActivateTab(3) },
   { key = "5", mods = mod.SUPER, action = act.ActivateTab(4) },
   { key = "6", mods = mod.SUPER, action = act.ActivateTab(5) },
   { key = "7", mods = mod.SUPER, action = act.ActivateTab(6) },
   { key = "8", mods = mod.SUPER, action = act.ActivateTab(7) },
   { key = "9", mods = mod.SUPER, action = act.ActivateTab(8) },

   -- panes: zoom+close pane
   { key = "x", mods = mod.SUPER_REV, action = act.TogglePaneZoomState },
   { key = "w", mods = mod.SUPER_REV, action = act.CloseCurrentPane({ confirm = false }) },

   -- panes: split panes
   { key = "o", mods = mod.SUPER_REV, action = act.SplitVertical({ domain = 'CurrentPaneDomain' }) },
   { key = "e", mods = mod.SUPER_REV, action = act.SplitHorizontal({ domain = 'CurrentPaneDomain' }) },
   { key = "-", mods = 'ALT', action = act.SplitVertical({ domain = 'CurrentPaneDomain' }) },
   { key = "-", mods = 'CTRL|ALT', action = act.SplitHorizontal({ domain = 'CurrentPaneDomain' }) },

   -- panes: navigation
   { key = "UpArrow", mods = mod.SUPER, action = act.ActivatePaneDirection('Up') },
   { key = "DownArrow", mods = mod.SUPER, action = act.ActivatePaneDirection('Down') },
   { key = "LeftArrow", mods = mod.SUPER, action = act.ActivatePaneDirection('Left') },
   { key = "RightArrow", mods = mod.SUPER, action = act.ActivatePaneDirection('Right') },

   -- panes: resize
   { key = "UpArrow", mods = mod.SUPER_REV, action = act.AdjustPaneSize{'Up',1} },
   { key = "DownArrow", mods = mod.SUPER_REV, action = act.AdjustPaneSize{'Down',1} },
   { key = "LeftArrow", mods = mod.SUPER_REV, action = act.AdjustPaneSize{'Left',1} },
   { key = "RightArrow", mods = mod.SUPER_REV, action = act.AdjustPaneSize{'Right',1} },
}

return {
   disable_default_key_bindings = false,
   leader = { key = 'Space', mods = mod.SUPER_REV },
   keys = keys,
}